package org.rebluh.hulunbuirtravelnetworkbackendframework.service;

import org.rebluh.hulunbuirtravelnetworkbackendframework.domain.FilterIcon;
import org.rebluh.hulunbuirtravelnetworkbackendframework.repository.FilterIconRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FilterIconService {
    @Autowired
    private FilterIconRepository filterIconRepository;
    @Autowired
    private MongoTemplate mongoTemplate;

    // 创建
    public FilterIcon createFilterIcon(FilterIcon filterIcon) {
        return filterIconRepository.save(filterIcon);
    }

    // 根据顺序获取全部的FilterIcons
    public List<FilterIcon> getAllFilterIcon() {
        return mongoTemplate.find(
                new Query().with(Sort.by(Sort.Order.asc("position"))),
                FilterIcon.class
        );
    }
}
